package com.D5Power.Editor
{
	import com.D5Power.Editor.EditorWindow.MapAttr;
	import com.D5Power.Editor.config.MouseStatus;
	
	import flash.events.Event;
	
	import org.aswing.JButton;
	import org.aswing.JMenuItem;
	import org.aswing.JPanel;
	import org.aswing.LayoutManager;
	import org.aswing.LoadIcon;
	
	/**
	 * 顶部工具栏
	 */ 
	public class ToolBox extends JPanel
	{
		
		private var _root:D5RpgEditor;
		
		public function ToolBox(layout:LayoutManager=null,editor:D5RpgEditor=null)
		{
			super(layout);
			_root = editor;
			init();
		}
		
		/**
		 * 开始处理
		 */ 
		private function init():void
		{
			var newButton:JButton = new JButton(null,new LoadIcon('EditorUI/icon2.png',16,16));
			newButton.addActionListener(newMap);
			newButton.setToolTipText('新建地图');
			
			var openButton:JButton = new JButton(null,new LoadIcon('EditorUI/icon3.png',16,16));
			openButton.addActionListener(openMap);
			openButton.setToolTipText('打开地图');
			
			var saveButton:JButton = new JButton(null,new LoadIcon('EditorUI/icon4.png',16,16));
			saveButton.addActionListener(saveMap);
			saveButton.setToolTipText('保存地图');

			var tileButton:JButton = new JButton(null,new LoadIcon('EditorUI/icon0.png',16,16));
			tileButton.addActionListener(showTile);
			tileButton.setToolTipText('显示/隐藏网格');
			
			var showOverButton:JButton = new JButton(null,new LoadIcon('EditorUI/icon6.png',16,16));
			showOverButton.addActionListener(showOver);
			showOverButton.setToolTipText('显示/隐藏透明碰撞');
			
			var runButton:JButton = new JButton(null,new LoadIcon('EditorUI/icon1.png',16,16));
			runButton.addActionListener(runMap);
			runButton.setToolTipText('运行地图');
			
			var overButton:JButton = new JButton(null,new LoadIcon('EditorUI/icon5.png',16,16));
			overButton.addActionListener(startDrawOver);
			overButton.setToolTipText('绘制透明碰撞区');
			
			var roadButton:JButton = new JButton(null,new LoadIcon('EditorUI/icon7.png',16,16));
			roadButton.addActionListener(addRoad);
			roadButton.setToolTipText('新增路点');
			
			
			append(newButton);
			append(openButton);
			append(saveButton);
			append(tileButton);
			append(showOverButton);
			append(runButton);
			append(overButton);
			append(roadButton);
		}
		
		/**
		 * 调用D5Menu中的控制事件
		 */ 
		private function showTile(e:Event):void
		{
			_root.Menu.updateShowTile();
		}
		
		/**
		 * 调用D5Menu中的控制事件
		 */ 
		private function showOver(e:Event):void
		{
			_root.Menu.updateShowOver();
		}
		
		/**
		 * 开启或关闭障碍物绘制模式
		 */ 
		private function startDrawOver(e:Event):void
		{
			if(_root.mouseStatus==MouseStatus.DRAW_OVER)
			{
				_root.Menu.updateShowOver(2);
				_root.mouseStatus = '';
			}else{
				_root.Menu.updateShowOver(1);
				_root.mouseStatus = MouseStatus.DRAW_OVER;
			}
			
		}
		
		/**
		 * 打开地图按钮
		 */ 
		private function openMap(e:Event):void
		{
			_root.Menu.openMap();
		}
		
		/**
		 * 保存地图按钮
		 */ 
		private function saveMap(e:Event):void
		{
			_root.Menu.saveMap(_root.Menu.filename);
		}
		
		/**
		 * 新建地图按钮
		 */ 
		private function newMap(e:Event):void
		{
			_root.newOrEditMap(MapAttr.NEWMAP);
		}
		
		/**
		 * 运行地图
		 */ 
		private function runMap(e:Event):void
		{
			_root.Run();
		}
		
		/**
		 * 增加路点
		 */ 
		private function addRoad(e:Event):void
		{
			_root.Shower.startAddObject('',LibResource.ROAD,'');
		}
	}
}